<template>
  <div class="app-container">
    <div class="button-margin"></div>
    <el-table
      v-loading="listLoading"
      :data="schoolAppList"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button @click="viewSchoolPatch(scope.row)" type="text" size="medium"
            >查看</el-button
          >
          <span>|</span>
          <el-button @click="viewSchoolPatch(scope.row)" type="text" size="medium"
            >检出</el-button
          >
        </template>
      </el-table-column>
      <el-table-column align="center" label="学校">
        <template slot-scope="scope">
          {{ scope.row.SCHOOLNAME }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="应用">
        <template slot-scope="scope">
          {{ scope.row.APPID }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="应用名">
        <template slot-scope="scope">
          {{ scope.row.APPNAME }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="当前版本">
        <template slot-scope="scope">
          {{ scope.row.VERSION }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="未升级补丁数">
        <template slot-scope="scope">
          {{ scope.row.COUNT }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="SVN路径">
        <template slot-scope="scope">
          {{ scope.row.SVNPATH }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="用户名">
        <template slot-scope="scope">
          {{ scope.row.USERNAME }}
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageIndex"
      :limit.sync="listQuery.pageSize"
      @pagination="getSchoolList"
    />

    <!-- 应用补丁弹窗 -->
    <el-dialog :title="schoolName +'-'+ appname+'-'+version" :visible.sync="schoolPatchVisible" width="60%">
      <div class="app-container">
        <el-table
          :data="schoolPatchList"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
        >
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <el-button @click="getPatchDetail(scope.row)" type="text" size="medium"
                >详情</el-button
              >
              <span v-if="scope.row.SJBZ == '0' && scope.row.STATE != '-1'">|</span>
              <el-button @click="updatePatch()" type="text" size="medium"
                v-if="scope.row.SJBZ == '0' && scope.row.STATE == '100'">升级</el-button
              >
            </template>
          </el-table-column>
          <el-table-column align="center" label="发布时间">
            <template slot-scope="scope"> 
              {{ scope.row.FBSJ }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="状态">
            <template slot-scope="scope"> 
              <div class="el-icon-check" v-if="scope.row.SJBZ == '1'" style="color:#67C23A">已升级</div>
              <div class="el-icon-magic-stick" v-if="scope.row.STATE == '100' && scope.row.SJBZ == '0'" style="color:#409EFF">可升级</div>
              <div class="el-icon-warning-outline" v-if="scope.row.STATE == '-1'" style="color:#F56C6C">不可升级</div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="schoolPatchTotal > 0"
          :total="schoolPatchTotal"
          :page.sync="patchListQuery.pageIndex"
          :limit.sync="patchListQuery.pageSize"
          @pagination="viewSchoolPatch(scope.row)"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="schoolPatchVisible = false">关闭</el-button>
      </span>
    </el-dialog>

    <!-- 补丁详情弹窗 -->
    <el-dialog title="补丁修改详情" :visible.sync="patchDetailVisible" width="40%">
      <div class="app-container">
        <el-table
          :data="patchDetail"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
        >
          <el-table-column align="center" label="修改路径">
            <template slot-scope="scope"> 
              {{ scope.row.PATH }}
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="patchDetailTotal > 0"
          :total="patchDetailTotal"
          :page.sync="patchListQuery.pageIndex"
          :limit.sync="patchListQuery.pageSize"
          @pagination="getPatchDetail(scope.row)"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="patchDetailVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import request from '@/utils/request'
import Pagination from '@/components/Pagination'
export default {
  components: { Pagination },
  data() {
    return {
      schoolAppList: null,
      schoolPatchList: null,
      schoolPatchDetail: null,
      listLoading: true,
      total: 0,
      schoolPatchTotal: 0,
      patchDetailTotal: 0,
      listQuery: {
        pageIndex: 1,
        pageSize: 20,
      },
      patchListQuery: {
        pageIndex: 1,
        pageSize: 10,
      },
      schoolPatchVisible: false,
      patchDetailVisible: false,
      handleClose: true,
      form: {},
      appname: null,
      version: null,
      schoolName: null
    }
  },
  created() {
    this.getSchoolList()
  },
  methods: {
    getSchoolList() {
      this.listLoading = true
      request({
        url: `${window.contextPath}/hrsvn/querySchoolAppList.do`,
        method: 'post',
        params: this.listQuery,
      }).then((response) => {
        ;(this.schoolAppList = response.rows),
          (this.total = response.total),
          (this.listLoading = false)
      })
    },
    viewSchoolPatch(data) {
      this.schoolPatchVisible = true;
      this.appname = data.APPNAME;
      this.version = data.VERSION;
      this.schoolName = data.SCHOOLNAME;
      var appid = data.APPID;
      var version = data.VERSION;
      var school = data.SCHOOL;
      var listQuery = this.listQuery;
      request({
        url: `${window.contextPath}/hrsvn/querySchoolPatchList.do`,
        method: 'post',
        params: {
            listQuery,
            appid,
            version,
            school
        }
      }).then((response) => {
        ;(this.schoolPatchList = response.rows),
          (this.schoolPatchTotal = response.total),
          (this.listLoading = false)
      })
    },
    getPatchDetail(data) {
      this.patchDetailVisible = true;
      var zbwid = data.WID;
      var patchListQuery = this.patchListQuery;
      request({
        url: `${window.contextPath}/hrsvn/queryPatchDetail.do`,
        method: 'post',
        params: {
            patchListQuery,
            zbwid
        }
      }).then((response) => {
        ;(this.patchDetail = response.rows),
          (this.patchDetailTotal = response.total),
          (this.listLoading = false)
      })
    },
    updatePatch() {
    }
  }
}
</script>